<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    canvas{
      border: 1px solid #ccc;
    }
  </style>
</head>
<body>
  <canvas width="600" height="400"></canvas>
  
</body>
<script>
  let canvas=document.querySelector("canvas")
  let ctx=canvas.getContext("2d")

  ctx.moveTo(100,100)
  ctx.lineTo(200,200)
  ctx.lineTo(300,100)
  ctx.lineTo(100,100)

  //描边
  // ctx.strokeStyle="red"
  // ctx.stroke()


  //填充
  ctx.fillStyle="red"
  ctx.fill()

  







</script>
</html>